package org.teamh.connection.json.handler;

import org.teamh.connection.json.event.JsonEventObject;
import org.teamh.game.Start;
import org.teamh.logic.datamodel.*;

public class TowerDescriptionHandler extends JsonMasterHandler {

	public TowerDescriptionHandler(Start start, DatamodelManager manager) {
		super(start, manager);
	}
	
	public boolean handleMsg(JsonEventObject json) {
		
		if (json.getSource().startsWith("TowerDescription")) {
			String ID = json.getSource();
			if (json.getProperty().equals("description")) {
				manager.getTowerDescription(ID).setDescription(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("name")) {
				manager.getTowerDescription(ID).setName(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("price")) {
				manager.getTowerDescription(ID).setPrice(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("coolDownMax")) {
				manager.getTowerDescription(ID).setCoolDownMax(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("damage")) {
				manager.getTowerDescription(ID).setDamage(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("range")) {
				manager.getTowerDescription(ID).setRange(Double.parseDouble(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("sellTime")) {
				manager.getTowerDescription(ID).setSellTime(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("sellValue")) {
				manager.getTowerDescription(ID).setSellValue(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("slowRate")) {
				manager.getTowerDescription(ID).setSlowRate(Double.parseDouble(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("slowTime")) {
				manager.getTowerDescription(ID).setSlowTime(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("splashRadius")) {
				manager.getTowerDescription(ID).setSplashRadius(Double.parseDouble(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("splashDamageReduction")) {
				manager.getTowerDescription(ID).setSplashDamageReduce(Double.parseDouble(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("upgradeable")) {
				manager.getTowerDescription(ID).setUpgradeable(Boolean.parseBoolean(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("upgradeTime")) {
				manager.getTowerDescription(ID).setUpgradeTime(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("level")) {
				manager.getTowerDescription(ID).setLevel(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("type")) {
				manager.getTowerDescription(ID).setType(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("color")) {
				manager.getTowerDescription(ID).setColor(json.getNewValue());
				return true;
			}
			return false;
		} else {
			return false;
		}
	}
}